package com.excuse.excusebuilder.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.excuse.excusebuilder.base.IBaseList;
import com.excuse.excusebuilder.base.ToastQueryListener;
import com.excuse.excusebuilder.base.ToastSaveListener;
import com.excuse.excusebuilder.bean.Option;
import com.excuse.excusebuilder.bean.Result;
import com.excuse.excusebuilder.bean.Type;
import com.excuse.excusebuilder.commen.util.MyToast;

import java.util.List;

import cn.bmob.v3.BmobQuery;

/**
 * Created by 鹏君 on 2017/4/18.
 */

public class AddExcuseActivityPresenter {
    private Context context;
    private IView activity;

    public AddExcuseActivityPresenter(Context context, IView activity) {
        this.context = context;
        this.activity = activity;
    }

    public void addExcuse(String typeStr, final String optionStr, final String resultStr) {
        if (TextUtils.isEmpty(typeStr) || TextUtils.isEmpty(optionStr) || TextUtils.isEmpty(resultStr)) {
            MyToast.showToast(context, "请填入完整信息~");
            return;
        }

        activity.showLoading(true);
        final Type type = new Type();
        type.setName(typeStr);
        type.save(new ToastSaveListener<String>(context, activity) {
            @Override
            public void onSuccess(String s) {

                final Option option = new Option(type, optionStr);
                option.save(new ToastSaveListener<String>(context, activity) {
                    @Override
                    public void onSuccess(String s) {

                        Result result = new Result(option, resultStr);
                        result.save(new ToastSaveListener<String>(context, activity) {
                            @Override
                            public void onSuccess(String s) {
                                activity.showLoading(false);
                                activity.finish();
                            }
                        });
                    }
                });
            }
        });
    }


    public interface IView extends IBaseList {

        void finish();
    }
}
